package pl.edu.agh.anomalyids.network.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import pl.edu.agh.anomalyids.network.Packet;

public class PacketReader {
	
	private static final Logger logger = LoggerFactory.getLogger(PacketReader.class);

	@SuppressWarnings("unchecked")
	public List<Packet> read(String filePath) {
		ObjectInputStream input = null;
		try {
			FileInputStream fileInput = new FileInputStream(filePath);
			input = new ObjectInputStream(fileInput);
			return (List<Packet>) input.readObject();
		} catch (IOException e) {
			logger.error("Error during packets serialization: " + e);
		} catch (ClassNotFoundException e) {
			logger.error("Cannot find Packet class: " + e);
		} finally {
			try {
				input.close();
			} catch (IOException e) {
				logger.error("Error closing output stream: " + e);
			}
		}
		
		return new ArrayList<Packet>();
	}
}

